package de.lns.tick;

import de.lns.render.MultiDraw;
import de.lns.render.RenderQueue;

/**
 * This class (or more accurately: each of it's subclasses)
 * represents one possible State for the Engine.<br>
 * Each State Should override the update method and 
 * define all code, belonging to that state, there.
 */
public abstract class State implements MultiDraw, Input {
	
	private static State active;
	
	private RenderQueue queue;
	
	/**
	 * Creates a new State object.
	 * @param queue - A <i>RenderQueue</i>, that contains all objects <br>
	 * which should be rendered by this State.
	 */
	protected State(RenderQueue queue) {
		this.queue = queue;
	}
	
	/**
	 * Makes this state tick once. <br>
	 */
	protected abstract void update();
	
	/**
	 * Gets called by <i>activate()</i>, when this State is activated:
	 */
	protected abstract void activated();
	
	/**
	 * Sets this State as the active state <br>
	 * and notifies it with a call of <i>activated()</i> <br>
	 * <i>State.active</i> will now return this State.
	 */
	public final void activate() {
		if(active != this){
			active = this;
			this.activated();
		}
	}
	
	/**
	 * Get the active game state.
	 * @return - the last state <i>activate()</i> was called on.
	 */
	public static State active() {
		return active;
	}
	
	@Override
	public RenderQueue queue() {
		return queue;
	}
	
}
